import ImagePicker from "react-native-image-picker";
import {
    Platform,
    Alert
} from 'react-native';
var img_path = "file:///storage/emulated/0/DCIM/";
var img_id = "165413213456416";
export default class OffLineImagePick {
    static showImage(_this){
        let options = {
            title: '选择图片',
            cancelButtonTitle: '取消',
            takePhotoButtonTitle: '拍照',
            chooseFromLibraryButtonTitle: '图片库',
            /* permissionDenied:{
                 title:"权限被拒绝",
                 text:"要求能够使用相机拍照并从库中选择图像",
                 reTryTitle:"重试",
                 okTitle:"确认",
             },*/
            cameraType: 'back',
            mediaType: 'photo',
            videoQuality: 'high',
            durationLimit: 10,
            maxWidth: 600,
            maxHeight: 600,
            aspectX: 2,
            aspectY: 1,
            quality: 0.8,
            angle: 0,
            allowsEditing: false,
            noData: false,
            storageOptions: {
                skipBackup: true,
                path: 'images'
            }
        };
        ImagePicker.showImagePicker(options,(response) => {
            if (response.didCancel) {
                console.log('User cancelled image picker');
            } else if (response.error) {
                let url=""
                let text=""
                if(response.error.indexOf("Photo")>-1){
                    text = "请允许应用访问您的手机相册";
                }else{
                    text = "请允许应用访问您的相机";
                }

                Alert.alert('提示',text,
                    [
                        {
                            text: '确定',
                        },
                    ],
                    {
                        cancelable: true,
                    });

            }

            else {

                let source;

                if (Platform.OS === 'android') {
                    source = {uri: response.uri, isStatic: true}
                } else {
                    source = {uri: response.uri.replace('file://', ''), isStatic: true}
                }
                if (Platform.OS === 'android') {
                    img_path = response.uri
                } else {
                    img_path = response.uri.replace('file://', '')
                }
                let data = {
                    "path":img_path,
                    "id":""
                }
                _this.getImgList(data);
            }
        });
    }
}